/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package battle.ship.utils;

import java.io.*;
import javax.xml.bind.DatatypeConverter;

/**
 *
 * @author Carlos
 */
public class Util {
     public static String serializableToString( Serializable o ) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        oos.writeObject(o);
        return DatatypeConverter.printBase64Binary(baos.toByteArray());
    }
     
     public static Object desserilizeFromString( String s ) throws IOException ,
                                                        ClassNotFoundException {
        byte [] data = DatatypeConverter.parseBase64Binary(s);
        ObjectInputStream ois = new ObjectInputStream( 
                                        new ByteArrayInputStream(  data ) );
        Object o  = ois.readObject();
        ois.close();
        return o;
    }
     
     
}
